use criterion::{black_box, criterion_group, criterion_main, Criterion};
use queue::queue::Queue;

fn queue_push_head_benchmark(c: &mut Criterion) {
    c.bench_function("queue_push_head", |b| {
        b.iter(|| {
            let mut queue = Queue::new();
            for i in 0..1000 {
                queue.push_head(black_box(i));
            }
        });
    });
}

fn queue_push_back_benchmark(c: &mut Criterion) {
    c.bench_function("queue_push_back", |b| {
        b.iter(|| {
            let mut queue = Queue::new();
            for i in 0..1000 {
                queue.push_back(black_box(i));
            }
        });
    });
}

fn queue_pop_head_benchmark(c: &mut Criterion) {
    let mut queue = Queue::new();
    for i in 0..1000 {
        queue.push_back(i);
    }
    c.bench_function("queue_pop_head", |b| {
        b.iter(|| {
            let mut queue = queue.clone();
            while let Some(_) = queue.pop_head() {}
        });
    });
}

fn queue_pop_tail_benchmark(c: &mut Criterion) {
    let mut queue = Queue::new();
    for i in 0..1000 {
        queue.push_back(i);
    }
    c.bench_function("queue_pop_tail", |b| {
        b.iter(|| {
            let mut queue = queue.clone();
            while let Some(_) = queue.pop_tail() {}
        });
    });
}

fn queue_peek_head_benchmark(c: &mut Criterion) {
    let mut queue = Queue::new();
    for i in 0..1000 {
        queue.push_back(i);
    }
    c.bench_function("queue_peek_head", |b| {
        b.iter(|| {
            black_box(queue.peek_head());
        });
    });
}

fn queue_peek_tail_benchmark(c: &mut Criterion) {
    let mut queue = Queue::new();
    for i in 0..1000 {
        queue.push_back(i);
    }
    c.bench_function("queue_peek_tail", |b| {
        b.iter(|| {
            black_box(queue.peek_tail());
        });
    });
}

fn queue_is_empty_benchmark(c: &mut Criterion) {
    let queue = Queue::<i32>::new();
    c.bench_function("queue_is_empty", |b| {
        b.iter(|| {
            black_box(queue.is_empty());
        });
    });
}

criterion_group!(
    benches,
    queue_push_head_benchmark,
    queue_push_back_benchmark,
    queue_pop_head_benchmark,
    queue_pop_tail_benchmark,
    queue_peek_head_benchmark,
    queue_peek_tail_benchmark,
    queue_is_empty_benchmark
);
criterion_main!(benches);